home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
CRON_1
/
STANDARD
/
BUFFERMG.H
next >
Wrap
Text File
|
1991-09-01
|
8KB
|
248 lines
#ifndef _BufferMgr_
#define _BufferMgr_
#ifndef NULL
#define NULL 0L
#endif
typedef enum {
BufferMemDflt = 0, // Allocate in current heap zone only.
BufferMemTemp, // Allocate in System 7 temporary memory space only.
BufferMemDfltTemp, // Try BufferMemDflt mode first, then BufferMemTemp mode.
BufferMemTempDflt // Try BufferMemTemp mode first, then BufferMemDftl mode.
} BufferAllocMethods;
Handle BufferCreate(long InitialSize, long ExpansionFactor, BufferAllocMethods AllocMethod);
void BufferDispose(Handle Buffer);
Ptr BufferOpen(Handle Buffer);
void BufferClose(Handle Buffer);
void BufferClear(Handle Buffer);
void BufferCompact(Handle Buffer);
Ptr BufferAdd(Handle Buffer, long DataSize, Ptr DataPtr);
void BufferDel(Handle Buffer, long DataSize);
Ptr BufferPtrGet(Handle Buffer);
Ptr BufferInfoGet(Handle Buffer, long *DataSize, long *ElementCount);
/* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Buffer Manager -- Procedure Summary
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
The Buffer Manager is a set of routines which take a lot of the
work out of maintiaing a growing block of relocatable memory. It
automatically handles expanding the block of memory to accomodate
any data you add to it, and helps make the process as efficient
as possible by automatically preallocating storage for the block.
The Buffer Manager doesn't do anything you couldn't do yourself
with Memory Manager routines, of course -- it just saves you all
that trouble.
Creating and Disposing of Buffers
Ñ BufferCreate
Ñ BufferDispose
Accessing Data in Buffers
Ñ BufferOpen
Ñ BufferClose
Cleaning-Up Buffers
Ñ BufferClear
Ñ BufferCompact
Adding and Deleting Data to/from Buffers
Ñ BufferAdd
Ñ BufferDel
Information on Buffers
Ñ BufferPtrGet
Ñ BufferInfoGet
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Creating and Disposing of Buffers
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
BufferCreate
╤╤╤╤╤╤╤╤╤╤╤╤
Handle BufferCreate(long InitialSize, long ExpansionFactor,
BufferAllocMethods AllocMethod);
BufferCreate creates a new buffer with InitialSize bytes immed-
iately reserved for its use. The buffer will be allocated in the
manner specified by the AllocMethod parameter. The function returns
a handle to the buffer, or NULL if the buffer could not be created.
Any time the buffer becomes full, it will automatically grow by a
minimum of ExpansionFactor bytes.
WARNING: Do not attemp to specify the BufferMemTemp, BufferMemTempDflt,
or BufferMemDfltTemp modes in the AllocMethod parameter
unless you have already verified that support for real,
tracked temporary memory is available. This support exists
in System 7, but not in previous systems. The Gestalt
function should be used to check for the availability of
these features. See IM VI pg. 28-37, 28-41.
BufferDispose
╤╤╤╤╤╤╤╤╤╤╤╤╤
void BufferDispose(Handle Buffer);
BufferDispose disposes of all memory associated with the buffer
specified by the Buffer parameter.
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Accessing Data in Buffers
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
BufferOpen
╤╤╤╤╤╤╤╤╤╤
Ptr BufferOpen(Handle Buffer);
BufferOpen locks the buffer in memory and returns a pointer to
beginning of your data in the buffer. Try not to keep the buffer
open longer than necessary since it might interfere with calls to
BufferAdd.
BufferClose
╤╤╤╤╤╤╤╤╤╤╤
void BufferClose(Handle Buffer);
BufferClose unlocks the buffer in memory IF there are no outstand-
ing calls to BufferOpen. Pointers to data in the buffer may become
invalid at any time following the final BufferClose call.
Note that BufferClose will only unlock the buffer when the number
of calls made to BufferOpen is equal to the number of calls made
to BufferClose. This prevents one procedure that was accessing data
in the buffer from inadvertantly unlocking the buffer while another
procedure is still trying to access data in the same buffer.
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Accessing Data in Buffers
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
BufferClear
╤╤╤╤╤╤╤╤╤╤╤
void BufferClear(Handle Buffer);
BufferClear clears the specified buffer. The buffer's physical size
is left unchanged, but both the logical size and element count are
set to zero. Use this routine when you want to retain the buffer for
future use, but you don't want to retain any of the data in it. If,
after calling BufferClear, you want to reclaim the memory formerly
occupied by the data in the buffer, call BufferCompact.
BufferCompact
╤╤╤╤╤╤╤╤╤╤╤╤╤
void BufferCompact(Handle Buffer);
BufferCompact compacts the specified buffer, reducing it's physical
size to match it's logical size as closely as possible. No data is
lost from the buffer.
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Adding and Deleting Data to/from Buffers
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
BufferAdd
╤╤╤╤╤╤╤╤╤
Ptr BufferAdd(Handle Buffer, long DataSize, Ptr DataPtr);
BufferAdd expands the specified buffer to accomodate DataSize add-
itional bytes, then uses BlockMove to copy DataSize bytes from the
location pointed to by DataPtr to the end of the buffer, if DataPtr
is not NULL. BufferAdd returns a pointer to the start of the data
copied into the buffer. If the buffer could not be expanded, the
pointer returned is NULL. Note that the pointer returned is not
guaranteed to remain valid unless the BufferOpen call has been used
to lock the buffer in memory. Calling BufferOpen immediately after
calling BufferAdd IS legal.
BufferDel
╤╤╤╤╤╤╤╤╤
void BufferDel(Handle Buffer, long DataSize);
BufferDel deletes DataSize bytes from the end of the buffer.
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Adding and Deleting Data to/from Buffers
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
BufferPtrGet
╤╤╤╤╤╤╤╤╤╤╤╤
Ptr BufferPtrGet(Handle Buffer);
BufferPtrGet returns a pointer to the beginning of the data in the
buffer. Note that the buffer is not guaranteed to be locked in mem-
ory, so the pointer returned may not remain valid after calls that
can move or purge memory. In general, it's best to use BufferOpen
since it CAN guarantee that the pointer will remain valid until the
next call to BufferClose.
BufferInfoGet
╤╤╤╤╤╤╤╤╤╤╤╤╤
Ptr BufferInfoGet(Handle Buffer, long *DataSize, long *ElementCount);
BufferInfoGet returns a pointer to the beginning of the data in the
buffer, in exactly the same manner (and with the same limitations) as
BufferPtrGet. In DataSize it returns the total number of bytes occu-
pied by your data in the buffer. In ElementCount it returns the num-
ber of elements in the buffer. A buffer's ElementCount is incremented
each time BufferAdd is called and decremented each time BufferDel is
used.
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
Internet: chrisj@emx.utexas.edu
UUCP: {husc6|uunet}!cs.utexas.edu!ut-emx!chrisj
BitNet: chrisj@utxvm.bitnet
AppleLink: chrisj@emx.utexas.edu@internet#
CompuServe: >INTERNET:chrisj@emx.utexas.edu
US Mail: Chris Johnson, 3311 Red River #305, Austin, TX 78705
╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
*/
#endif